﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

public partial class index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //使用dom读取xml信息
        XmlDocument myXml = new XmlDocument();
        //把服务器虚拟路径转为物理路径
        string path = Server.MapPath("~/Leadin.xml");
        //读取XML文件
        myXml.Load(path);
        //获取xml的根节点
        XmlNode root = myXml.DocumentElement;
        //构造表格的一行，用于显示一级导航栏
        TableRow leadinBar = new TableRow();
        Lv1Table.Controls.Add(leadinBar);
        for (int i = 0; i < root.ChildNodes.Count; i++)
        {
            LinkButton myLinkBtn = new LinkButton();
            myLinkBtn.Click += LeadinBar_Click;
            myLinkBtn.Text = root.ChildNodes[i].Attributes[0].Value.ToString();
            TableCell myCell = new TableCell();
            myCell.Controls.Add(myLinkBtn);
            leadinBar.Controls.Add(myCell);
        }
        if (!IsPostBack)
        {
            XmlTree.DataFile = "~/Leadin.xml";
            XmlTree.XPath = "/leadin/node[1]";
            TreeView1.DataSourceID = "XmlTree";
        }
    }

    protected void LeadinBar_Click(object sender, EventArgs e)
    {
        XmlTree.DataFile = "~/Leadin.xml";
        //将1级导航栏的目录信息传给TreeView
        XmlTree.XPath = "/leadin/node[@name='" + ((LinkButton)(sender)).Text + "']";
        TreeView1.DataSourceID = "XmlTree";
        //将1级导航栏的目录信息传给contentFrame，打开搜索页面
        string path = "Pages/search.aspx?index=" + ((LinkButton)sender).Text;
        contentFrame.Attributes["src"] = path;
    }

    protected void TreeView_Click(object sender, EventArgs e)
    {
        //将被点击TreeNode的目录信息传给contentFrame，打开搜索页面
        string path = "Pages/search.aspx?index=" + ((TreeView)sender).SelectedNode.Text;
        contentFrame.Attributes["src"] = path;
    }
}
